<?php
/**
 * +----------------------------------------------------------------------
 * | [ DO WHAT YOU LOVE AND FUCK THE REST ]
 * +----------------------------------------------------------------------
 * | EMAIL: < 931274989@qq.com >
 * +----------------------------------------------------------------------
 * | WECHAT: xzc016
 * +----------------------------------------------------------------------
 * | 系统设置
 * +----------------------------------------------------------------------
 */
namespace app\admin\controller;

use app\common\model\System as SystemModel;
use app\admin\validate\System as SystemValidate;

use think\facade\View;

class System extends Base
{
  // 系统设置查看
  public function index() {
    $system = SystemModel::where('web','web')->find();
    View::assign('system',$system);
    return View::fetch();
  }

  // 修改设置
  public function edit() {
    if($this->request->isPost()) {
      $post = $this->request->post();
      //验证 
      (new SystemValidate())->goCheck();
      if(empty($post['is_log'])) {
          $post['is_log'] = 0;
      } else {
          $post['is_log'] = $post['is_log'];
      }
      if(empty($post['code'])) {
        $post['code'] = 0;
      } else {
        $post['code'] = $post['code'];
      }

      if(false == SystemModel::where('web','web')->save($post)) {
        return error('提交失败');
      } else {
        adminLog();
        return success('提交成功','admin/System/index');
      }
    }
  }

}

?>